"use strict";
const path = require("path");
const resolve = (dir) => path.join(__dirname, dir);

module.exports = {
  runtimeCompiler: true,
  publicPath: "/",
  assetsDir: "static",
  configureWebpack: {
    resolve: {
      alias: {
        "@": resolve("src"),
      },
    },
    output: {
      library: `NewFrontTemplate`,
      libraryTarget: "umd", // 把微应用打包成 umd 库格式
      jsonpFunction: `webpackJsonp_NewFrontTemplate`,
    },
  },
  // css: {
  //   loaderOptions: {
  //     scss: {
  //       prependData: `@import "~@/assets/theme/var.scss";`,
  //     },
  //   },
  // },
  devServer: {
    port: process.env.VUE_APP_PORT,
    headers: {
      "Access-Control-Allow-Origin": "*", // 主应用获取子应用时跨域响应头
    },
    https: false,
    hotOnly: false,
    disableHostCheck: true,
    proxy: {
      "/mock/api": {
        target: process.env.VUE_APP_API_URL,
        changeOrigin: true,
        pathRewrite: {
          "^/mock/api": "", // rewrite path
        },
      },
      // 配置跨域
      "/server": {
        target: process.env.VUE_APP_ACT_API,
        ws: true,
        changOrigin: true,
        pathRewrite: {
          "^/server": "",
        },
      },
    },
  },
  chainWebpack(config) {
    // config.plugins.delete("preload");
    // config.plugins.delete("prefetch");
    // set svg-sprite-loader
    config.module.rule("svg").exclude.add(resolve("src/assets/icons")).end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/assets/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]",
      })
      .end();
  },
};
